//storag二次封装
import config from './../config'
export default {
  setItem(key, val) {
    let storage = this.getStorage()
    storage[key] = val
    window.localStorage.setItem('EMS', JSON.stringify(storage))
    var newStorageEvent = document.createEvent('StorageEvent');
    newStorageEvent.initStorageEvent('setItem', false, false, key, null, val, null, null);
    window.dispatchEvent(newStorageEvent);
  },
  getItem(key) {
    return this.getStorage()[key]
  },
  getStorage() {
    return JSON.parse(window.localStorage.getItem('EMS') || '{}')
  },
  clearItem(key) {
    let storage = this.getStorage()
    delete storage[key]
    window.localStorage.setItem('EMS', JSON.stringify(storage))
  },
  clearAll() {
    window.localStorage.clear()
  }
}